<template>
	<view class="record">
		<view v-for="(item, index) in listData" :key="index" class="grid-body content-box" @click="link(item)">
			<view class="info flex">
				<image class="icon" src="/static/images/online-examination/icon-examination.png" />
				<view class="ml-20 info-right">
					<view class="title mt-10">{{ item.paperName }}</view>
					<view class="my-10 font-12 color-BBBBBB">合格分/满分：{{ item.passScore }}/{{item.totalScore}}</view>
					<view class="my-10 font-12 color-BBBBBB">我的成绩：{{ item.score }}</view>
				</view>
			</view>
			<view class="footer">
				<view class="font-12 color-BBBBBB">
					交卷时间：{{ item.submitTime | format }}</view>
			</view>
			<image class="icon-right1" :src="`/static/images/online-examination/icon-${getIconSubffix(item)}.png`" />
		</view>
	</view>
</template>

<script>
	import {
		getSimulationTestRecord
	} from '@/api/educational-training/simulation-test.js'
	import dayjs from 'dayjs'
	export default {
		name: 'online-record',
		components: {},
		props: {},
		data() {
			return {
				listData: [],
				queryParams: {
					pageSize: 10,
					pageNum: 1
				},
				total: 0
			}
		},
		filters: {
			format(val) {
				if (!val) return val
				return dayjs(val).format('YYYY/MM/DD HH:mm')
			}
		},
		created() {
			this.getList()
		},
		onPullDownRefresh() {
			this.initData()
		},
		onReachBottom() {
			this.queryParams.pageNum++
			this.getList()
		},
		methods: {
			initData() {
				this.queryParams.pageNum = 1
				this.total = null
				this.getList()
			},
			async getList() {
				const {
					total,
					rows
				} = await getSimulationTestRecord(this.queryParams).finally(() => uni.stopPullDownRefresh())
				this.listData = this.queryParams.pageNum === 1 ? rows : [...this.listData, ...rows]
				this.total = total
			},
			link({
				id
			}) {
				uni.navigateTo({
					url: `/pages/work/mock-test/mock-test-detail?id=${id}`
				})
			},

		},
		computed: {
			getIconSubffix() {
				return (data) => {
					if (data.passLabel === '缺考') {
						return 'defect'
					} else {
						if (data.passLabel === '合格') {
							return 'p'
						} else {
							return 'l'
						}
					}
				}
			},
		},
		onPullDownRefresh() {
			this.getList()
		},
	}
</script>

<style scoped lang="scss">
	.record {
		margin-top: 30rpx;
	}

	.content-box {
		margin-bottom: 30rpx;
		padding: 30rpx 30rpx 20rpx 30rpx;
		position: relative;

		.info {
			position: relative;
			justify-content: space-between;
			align-items: center;
		}

		.info-right {
			flex: 1;
			height: 150rpx;
		}

		image {
			width: 150rpx;
			height: 150rpx;
		}

		.title {
			color: #333333;
			font-size: 32rpx;
			font-weight: bold;
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden; //溢出内容隐藏
			text-overflow: ellipsis; //文本溢出部分用省略号表示
			display: -webkit-box; //特别显示模式
			-webkit-line-clamp: 2; //行数
			line-clamp: 2;
			-webkit-box-orient: vertical; //盒子中内容竖直排列
			word-break: break-all;
		}

		.time {
			font-size: 26rpx;
			color: #999999;
			font-weight: 400;
			margin-top: 10rpx;
		}

		.submit {
			position: absolute;
			right: 0;
			bottom: 0;
			width: auto;
			line-height: 50rpx;
			height: 50rpx;
			font-size: 28rpx;
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			background: #c4c088;
			padding: 0 24rpx;

			&.disabled {
				background: #ccc;
			}
		}

		.footer {
			margin-top: 20rpx;
			padding-top: 20rpx;
			border-top: 1px solid #d5d7e3;
		}

		.icon-right1 {
			width: 170rpx;
			height: 150rpx;
			position: absolute;
			right: 70rpx;
			bottom: 50rpx;
			display: block;
		}
	}
</style>